package org.sjs.dreamfly.model.ixigua

import org.sjs.dreamfly.common.util.LogUtil
import org.sjs.dreamfly.model.MovieInfo

data class Data(
    var banner: Banner?,
    var blockFeed: BlockFeed?,
    var cluster: Cluster?,
    private var feed: Feed?,
    private var channelFeed: Feed?,
    var filter: List<Filter>?
) {
    fun getMovieList(): List<MovieInfo> {
        if (feed != null && feed?.Data != null && feed?.Data?.isNotEmpty() == true) {
            return toMovieList(feed?.Data)
        } else if (channelFeed != null && channelFeed?.Data != null && channelFeed?.Data?.isNotEmpty() == true) {
            return toMovieList(channelFeed?.Data)
        }
        return emptyList()
    }

    private fun toMovieList(data: List<Album>?): List<MovieInfo> {
        val result = mutableListOf<MovieInfo>()
        data?.forEachIndexed { index, item ->
            if (item == null) {
                LogUtil.e("$index is null")
            } else {
                val movieInfo = item.toMovieInfo()
                result.add(movieInfo)
            }
        }
        return result
    }
}